1 00:00:00,240 --> 00:00:04,470 All right, so today I'm going to make things happen with our part using a script. 2 00:00:04,470 --> 00:00:07,440 So I'm going to change the properties of this part using a script. 3 00:00:07,440 --> 00:00:08,550 That'll be pretty cool. 4 00:00:08,580 --> 00:00:11,970 I'm using my first game from the last video because it's convenient. 5 00:00:11,970 --> 00:00:16,080 You could use a fresh world, but go ahead and add a part and give it a unique name. 6 00:00:16,080 --> 00:00:17,490 I just called it my part. 7 00:00:17,490 --> 00:00:20,580 Now I have this variable script under here from the last video. 8 00:00:20,580 --> 00:00:22,710 I'm going to disable it because we don't need it. 9 00:00:22,980 --> 00:00:23,850 There we go. 10 00:00:23,850 --> 00:00:30,570 I'm going to go to the part, hit the plus, add a script KU Let's rename the script. 11 00:00:30,570 --> 00:00:32,850 I'll call it Change It. 12 00:00:32,850 --> 00:00:37,800 I used a capital C and a capital I get some camel case in there. 13 00:00:37,800 --> 00:00:38,970 That's what they call that. 14 00:00:39,240 --> 00:00:40,680 I can get rid of this. 15 00:00:40,830 --> 00:00:45,780 And before I start scripting, I'm going to take a quick look at the world. 16 00:00:46,140 --> 00:00:47,460 Click on this part. 17 00:00:47,460 --> 00:00:51,570 I'm going to look at some of the properties I want to change, basically brick color. 18 00:00:51,570 --> 00:00:53,370 I want to change the color, right? 19 00:00:53,370 --> 00:00:59,220 You could do that automatically, but you can also do with a script and hit control Z to change it back. 20 00:00:59,460 --> 00:01:02,310 I'm going to go down to transparency. 21 00:01:02,310 --> 00:01:04,770 That's another easy property to change. 22 00:01:04,770 --> 00:01:09,330 So transparency of zero means the part is opaque. 23 00:01:09,330 --> 00:01:12,090 You can't see through it 100%. 24 00:01:12,090 --> 00:01:14,790 Transparent is actually a one. 25 00:01:14,790 --> 00:01:18,030 So the scale is from 0 to 1. 26 00:01:18,030 --> 00:01:18,960 You can't see. 27 00:01:18,960 --> 00:01:19,710 You can't see it. 28 00:01:19,710 --> 00:01:20,610 You can see right through it. 29 00:01:20,610 --> 00:01:23,040 You see the outline when you select it, but that's about it. 30 00:01:23,310 --> 00:01:26,400 Now, if you make it to, it's not going to be any more transparent. 31 00:01:26,400 --> 00:01:28,410 The scale is 0 to 1. 32 00:01:28,680 --> 00:01:32,160 All right, let's make it 0.8, which is 80%. 33 00:01:32,160 --> 00:01:32,730 Right. 34 00:01:32,730 --> 00:01:34,920 80% of one is 0.8. 35 00:01:35,220 --> 00:01:36,660 You can kind of see it. 36 00:01:37,410 --> 00:01:39,240 That's like a little outline there. 37 00:01:39,630 --> 00:01:40,800 That's pretty cool. 38 00:01:40,800 --> 00:01:43,050 Let's go back and change that. 39 00:01:43,080 --> 00:01:46,350 Go to my part, change that transparency back to zero. 40 00:01:46,350 --> 00:01:48,210 And let's do that with a script. 41 00:01:48,780 --> 00:01:49,620 All right. 42 00:01:49,860 --> 00:01:50,850 Change it. 43 00:01:51,480 --> 00:01:53,070 How do we get a variable? 44 00:01:53,070 --> 00:01:57,180 For our part, we need to store my part in a variable. 45 00:01:57,180 --> 00:02:00,420 Once you get that, you're well on your way. 46 00:02:00,420 --> 00:02:05,340 Well, we know we have a scope modifier called local, and then we need a variable. 47 00:02:05,340 --> 00:02:06,810 We can call whatever we want. 48 00:02:06,900 --> 00:02:08,670 I think I'll just call it part. 49 00:02:09,720 --> 00:02:13,920 Now to get that part, we have the special word called script. 50 00:02:13,920 --> 00:02:15,300 Script is cool. 51 00:02:15,300 --> 00:02:17,520 It means this script. 52 00:02:17,520 --> 00:02:19,320 It's the same in every script. 53 00:02:19,320 --> 00:02:24,870 If you just say script, it means the script that you are actually typing in or running at the time. 54 00:02:25,020 --> 00:02:33,030 There's a property on script and actually on all game objects and you access a property with a dot called 55 00:02:33,030 --> 00:02:33,990 parent. 56 00:02:34,560 --> 00:02:35,010 All right. 57 00:02:35,010 --> 00:02:39,660 So if we mean this script, we mean change it. 58 00:02:39,660 --> 00:02:42,270 The parent is my part. 59 00:02:42,270 --> 00:02:44,730 You can kind of see that relationship, right? 60 00:02:44,760 --> 00:02:46,560 A parent child relationship. 61 00:02:46,560 --> 00:02:48,240 That's the parent my part. 62 00:02:48,360 --> 00:02:54,180 Also, if you click change it and you look at parent, it says my part. 63 00:02:54,180 --> 00:02:56,640 So it actually tells you these are the properties. 64 00:02:57,360 --> 00:02:58,110 Cool. 65 00:02:58,110 --> 00:03:04,530 Now we have essentially right here a reference to my part. 66 00:03:04,530 --> 00:03:10,500 We're going to stick it in that variable and then we're going to see if we can print out the name. 67 00:03:10,500 --> 00:03:12,840 My part, because that's his name. 68 00:03:12,840 --> 00:03:21,960 So print the parts name is equal to and I'll just say part dot name. 69 00:03:21,960 --> 00:03:26,820 Name is also a property of part if you go to my part. 70 00:03:28,070 --> 00:03:29,900 Name my part. 71 00:03:30,110 --> 00:03:31,970 It should print out my part. 72 00:03:32,270 --> 00:03:34,640 That's a go to view output. 73 00:03:34,640 --> 00:03:38,840 And then we'll hit this little triangle thing to play it. 74 00:03:38,890 --> 00:03:40,190 Oh, look at that. 75 00:03:40,490 --> 00:03:42,470 The part's name is my part. 76 00:03:42,500 --> 00:03:43,670 I'll make it a little bigger. 77 00:03:43,790 --> 00:03:45,080 There we go. 78 00:03:45,110 --> 00:03:46,170 We got it. 79 00:03:46,190 --> 00:03:47,930 We got the name of that part. 80 00:03:48,870 --> 00:03:49,630 Cool. 81 00:03:50,220 --> 00:03:51,640 Now, what can we do with it? 82 00:03:51,660 --> 00:03:53,680 Let's change the transparency. 83 00:03:53,700 --> 00:03:55,680 Let's make it a little bit invisible. 84 00:03:55,890 --> 00:03:57,900 But we want to see it when we go in the world. 85 00:03:57,900 --> 00:04:00,780 We want to see it turn invisible. 86 00:04:01,080 --> 00:04:03,240 I'm going to go well, partially invisible. 87 00:04:03,240 --> 00:04:04,560 We still want to be able to see it. 88 00:04:04,860 --> 00:04:08,790 I'm going to go and do this weight function. 89 00:04:09,090 --> 00:04:10,620 It's a Roblox function. 90 00:04:10,710 --> 00:04:14,520 It gives you a little bit of a of a definition of what it does. 91 00:04:14,520 --> 00:04:16,890 It's going to yield the thread, actually. 92 00:04:16,890 --> 00:04:22,770 It's going to yield this script so that it doesn't run for this many seconds. 93 00:04:23,040 --> 00:04:24,390 We'll say 6 seconds. 94 00:04:24,390 --> 00:04:27,930 That'll give us enough time to get in the world and find the part. 95 00:04:28,590 --> 00:04:28,890 All right. 96 00:04:28,890 --> 00:04:29,760 So we're going to wait. 97 00:04:29,760 --> 00:04:31,060 Everything else is running in the game. 98 00:04:31,060 --> 00:04:32,400 It's just yielding this script. 99 00:04:32,700 --> 00:04:34,710 It's stopping, it's waiting. 100 00:04:35,100 --> 00:04:40,200 And then after 6 seconds, we're going to say part dot transparency. 101 00:04:40,200 --> 00:04:40,710 Look at that. 102 00:04:40,710 --> 00:04:42,000 We've got IntelliSense. 103 00:04:42,000 --> 00:04:44,760 That DOT is the property operator. 104 00:04:44,760 --> 00:04:46,230 We can access the properties. 105 00:04:46,230 --> 00:04:52,340 When we hit a T, we get this IntelliSense that says, hey, what do you mean transparency, maybe? 106 00:04:52,350 --> 00:04:54,000 Oh, yeah, transparency. 107 00:04:54,540 --> 00:04:58,500 And now we could say, I don't know, 0.5. 108 00:04:58,680 --> 00:04:59,580 Let's try that. 109 00:05:00,000 --> 00:05:01,290 Go ahead and play it. 110 00:05:04,280 --> 00:05:05,240 There's our part. 111 00:05:08,060 --> 00:05:08,900 Boom. 112 00:05:09,200 --> 00:05:12,680 With that 50% transparency, you can kind of see through it. 113 00:05:13,640 --> 00:05:14,530 Nice. 114 00:05:14,540 --> 00:05:19,430 Let's make it become less and less transparent over time. 115 00:05:19,430 --> 00:05:20,690 Now, we can't really blend it. 116 00:05:20,720 --> 00:05:22,370 We don't know loops and stuff like that. 117 00:05:22,370 --> 00:05:26,720 We don't know a lot of cool gaming techniques, but we could do this manually. 118 00:05:26,750 --> 00:05:36,860 We could say, Wait one second, and then we'll say part transparency and maybe let's make it like point 119 00:05:36,860 --> 00:05:47,720 seven and then wait another second part dot transparency equals point nine. 120 00:05:47,750 --> 00:05:51,770 You might just see an outline of it very barely and you can make it one. 121 00:05:51,770 --> 00:05:53,180 So it's completely invisible. 122 00:05:53,180 --> 00:05:57,650 But I think what I'm going to do after another second is just make it opaque again. 123 00:05:57,770 --> 00:06:00,500 So do a T transparency. 124 00:06:01,820 --> 00:06:03,690 Opaque is zero. 125 00:06:03,710 --> 00:06:04,850 Can't see through it. 126 00:06:05,330 --> 00:06:06,980 All right, let's try it. 127 00:06:10,750 --> 00:06:11,710 There's our part. 128 00:06:14,450 --> 00:06:18,640 Now it's turning very oh, you barely see it at point nine. 129 00:06:18,650 --> 00:06:19,390 That's pretty cool. 130 00:06:19,400 --> 00:06:20,870 And then went back to opaque. 131 00:06:21,410 --> 00:06:22,410 Sweet. 132 00:06:22,430 --> 00:06:23,720 What else can we do? 133 00:06:24,380 --> 00:06:26,300 Anything in this list? 134 00:06:26,570 --> 00:06:30,800 And it's going to take a few videos to get through some of the cooler stuff, but I'm going to try and 135 00:06:30,800 --> 00:06:32,660 go quickly so I don't bore you too much. 136 00:06:32,810 --> 00:06:35,180 Here's brick color, brick color and color. 137 00:06:35,210 --> 00:06:41,200 They work together, but brick color gives you names of colors like blue, right? 138 00:06:41,210 --> 00:06:43,730 Or green or lime green. 139 00:06:44,540 --> 00:06:45,530 This is a really blue. 140 00:06:45,530 --> 00:06:48,460 This is a really this is actually called really blue. 141 00:06:48,470 --> 00:06:49,010 Right. 142 00:06:49,520 --> 00:06:49,880 All right. 143 00:06:49,880 --> 00:06:51,530 Let's let's do that with code. 144 00:06:51,530 --> 00:06:54,380 Let's go ahead and make that control, Z. 145 00:06:54,710 --> 00:06:55,580 There you go. 146 00:06:55,670 --> 00:06:57,560 Medium stone, gray control. 147 00:06:57,560 --> 00:06:59,780 Z undoes things. 148 00:07:00,080 --> 00:07:05,300 Let's go to change it after our little transparency experiment. 149 00:07:05,300 --> 00:07:07,250 Let's wait another second. 150 00:07:07,610 --> 00:07:10,430 Let's change the brick color. 151 00:07:10,430 --> 00:07:15,740 So if we say part B, ooh, look at that brick color. 152 00:07:15,890 --> 00:07:16,640 Cool. 153 00:07:16,850 --> 00:07:19,070 I'm going to click on it now. 154 00:07:19,070 --> 00:07:20,480 Brick color doesn't take a number. 155 00:07:20,480 --> 00:07:22,340 Brick color takes a brick color. 156 00:07:22,340 --> 00:07:24,260 Just one of those things you got to know. 157 00:07:26,520 --> 00:07:32,130 So we got a little bee there good that our IntelliSense gave us our bird color so we don't even have 158 00:07:32,130 --> 00:07:33,030 to know that much. 159 00:07:33,480 --> 00:07:37,410 Let's do a dot and I will make that red. 160 00:07:38,100 --> 00:07:46,110 So we have some pre defined functions for colors and I'm going to show you how to do another color because 161 00:07:47,790 --> 00:07:58,710 if we do part dot brick color, you will notice brick color only has oops, I need a dot a few of these 162 00:07:58,710 --> 00:08:00,120 predefined colors. 163 00:08:00,120 --> 00:08:01,890 Not everything in the palette. 164 00:08:01,890 --> 00:08:09,750 You do have a palette object, but if you want like lime green, if we click on part, open that thing 165 00:08:09,750 --> 00:08:10,290 up. 166 00:08:10,410 --> 00:08:15,780 You see that lime green right there that is not part of the dot. 167 00:08:15,780 --> 00:08:18,900 And then with a function we need to make that special. 168 00:08:18,900 --> 00:08:23,160 So we will do something called new, right? 169 00:08:23,160 --> 00:08:28,350 It will instantiate a new color object and then we do the speech quotes. 170 00:08:28,380 --> 00:08:38,790 Now you can get everything in the palette lime green cool as wait another second, we'll do part and 171 00:08:38,790 --> 00:08:42,390 we have this other cool function in brick color. 172 00:08:42,570 --> 00:08:44,160 I know we haven't done functions yet. 173 00:08:44,160 --> 00:08:45,210 Just trust me on it. 174 00:08:45,210 --> 00:08:47,100 We do this dot random. 175 00:08:47,100 --> 00:08:50,970 We'll get a random color so it'll be different every time we run the game. 176 00:08:51,960 --> 00:08:58,740 Well, by chance it could be the same two times in a row, but typically it's the different area. 177 00:08:58,770 --> 00:09:00,240 We're going to watch it turn invisible. 178 00:09:02,230 --> 00:09:02,910 Yeah. 179 00:09:02,920 --> 00:09:03,730 There you go. 180 00:09:04,000 --> 00:09:04,810 Cool. 181 00:09:04,840 --> 00:09:08,320 Opaque red, lime green. 182 00:09:08,320 --> 00:09:10,480 And then there's our random color. 183 00:09:10,570 --> 00:09:15,190 All right, so the next video, let's start changing sizes and possessions. 184 00:09:15,190 --> 00:09:16,840 That that'll be pretty cool, too.